﻿@{
    ViewBag.Title = "Overview over all titles";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<div id="PresentationBox">
    <!-- ng-app="publicModule" ng-controller="AllTitlesController as titleCtrl" -->
    <div>

        <table class="DataPresentationtable" id="allTitles">
            <tr>
                <td><center><img src = "/Content/images/loading.gif" />loading data...</center></td>
            </tr>
        </table>
    </div>
</div>

<script type="text/javascript">
    //var dataTable = $('#titlesTable').DataTable({
    //    "bFilter": false,
    //    "bInfo": false
    //});
    
    var dataSet = [];
    $(document).ready(function () {
        $.getJSON("/api/title", function (data) {
            $.each(data, function (key, val) {
                console.log(val);

                var title = [];
                //title.Title = val.Title.BookTitle;

                title.Title = "<a href='/Title/Get/" + val.Title.TitleId + "'>" + val.Title.BookTitle + "</a>";

                title.Loanables = val.Loanables.length;
                title.EditionNumber = val.Title.EditionNumber;
                title.EditionYear = val.Title.EditionYear;
                title.Publisher = val.Title.Publisher.Name;

                dataSet.push(title);
            });

            $('#allTitles').DataTable({
                "bFilter": false,
                "data": dataSet,
                "columns": [
                    { "data": "Title", "title": "Title", "sWidth": "60%" },
                    { "data": "Loanables", "title": "Loanables", "sWidth": "10%" },
                    { "data": "EditionNumber", "title": "Edition", "sWidth": "10%" },
                    { "data": "EditionYear", "title": "Year", "sWidth": "10%" },
                    { "data": "Publisher", "title": "Publisher", "sWidth": "10%" }
                ]
            });

            //remove ugly DataTable css
            $('#allTitles').removeClass("dataTable");
        });
    });
</script>